<?php
require_once(dirname(__FILE__) . '/../include/config.inc.php');
require_once "function.php";

//工单提交处理
$post_time = time();
$post_time2 = date("Y-m-d H:i:s", time());
$nowtime = time();

$h = date("H", time());
$h = intval($h);
$d = date("d", time());
$d = intval($d);


// 列出系统中 抢单 任务
$sql_order_qiang = "SELECT id,manageid,post_time,apply_device,school,truename,mobile  FROM  `#@__order`  where    jindu='3' and mode='q' and manageid=''  and is_delete=0   order by id desc   ";
$dosql->Execute($sql_order_qiang);
while ($row_qiang = $dosql->GetArray()) {
    $orderid = $row_qiang['id'];
    $orderidname = date('Ymd', $row_qiang['post_time']) . "-" . $orderid;  //工单号
    $repairname = getRepairMode($row_qiang['apply_device']);  //任务名称
    $addtime = $row_qiang['post_time'];
    $school = $row_qiang['school'];
    $truename = $row_qiang['truename'];
    $mobile = $row_qiang['mobile'];
    $apply_time = date("Y-m-d H:i:s", $row_qiang['post_time']);
    //超过指定时间 后进行系统 指派模式
    if ($post_time - $addtime > $cfg_qiangout * 60) {
        //列出 工程师 计算忙闲状态
        // 1 获取抢单的工程师

        $qiang_user = array();
        $user_do_num = array();
        $no_working_openid = array();
        $qiang_openid = "";
        $xian_arr = array();
        $xian_openid_arr = array();
        $dosql->Execute("SELECT `openid`,`id`,`truename` FROM  `#@__user`  WHERE level='3' and qiang='1'  ORDER BY id asc");
        while ($row_qiang = $dosql->GetArray()) {

            $user_id = $row_qiang['id'];
            //2 列出处理中的订单
            $do_num_count = 0;
            $do_order = $dosql->GetOne("select count(id) as num from `#@__order`  where jindu<5 and jindu>0  and FIND_IN_SET('$user_id',manageid) and is_delete=0 ");
            if (is_array($do_order) && isset($do_order['num'])) {
                $do_num_count = $do_order['num'];
            }
            //找出闲人
            if ($do_num_count == 0) {
                $no_working_openid[] = $row_qiang['openid'];
            }
            $row_qiang['do_num_count'] = $do_num_count;
            $user_do_num[] = $do_num_count;
            $qiang_user[] = $row_qiang;

        }
        //对相对空闲的工程师进行派单
        $zuixian = min($user_do_num); //获取最小的处理工单数量
        $xian_arr = array_keys($user_do_num, $zuixian);
        foreach ($xian_arr as $key => $val) {
            $xian_openid_arr[] = $qiang_user[$val];
        }
        //抽取随机人员
        $rndKey = array_rand($no_working_openid);
        $qiang_user = $xian_openid_arr[$rndKey];
        $qiang_openid = $qiang_user['openid'];
        $qiang_user_id = $qiang_user['id'];
        if ($qiang_openid != "") {
            //开始智能分配
            $orderidname = date('Ymd', time()) . "-" . $orderid;
            //封装为json格式的数据

            $send_body['touser'] = $qiang_openid;
            $send_body['template_id'] = $cfg_sendorder;
            $send_body['url'] = $cfg_weburl . 'wx/morderDetail.php?orderid=' . $orderid;
            $send_body['data']['first']['value'] = "📢 您好,抢单没有人接单,系统智能下发任务。请处理";
            $send_body['data']['first']['color'] = "#FF0000";
            $send_body['data']['keyword1']['value'] = $orderidname;
            $send_body['data']['keyword1']['color'] = "#173177";
            $send_body['data']['keyword2']['value'] = $repairname;
            $send_body['data']['keyword2']['color'] = "#FF0000";
            $send_body['data']['keyword3']['value'] = "💗" . $school;
            $send_body['data']['keyword3']['color'] = "#0e48cb";
            $send_body['data']['keyword4']['value'] = $truename;
            $send_body['data']['keyword4']['color'] = "#0e48cb";
            $send_body['data']['keyword5']['value'] = $mobile;
            $send_body['data']['keyword5']['color'] = "#0e48cb";
            $send_body['data']['remark']['value'] = "👉系统根据忙闲度自动派单，如有情况请转单为其他工程师，谢谢！。服务热线:" . $cfg_hotline . "👈";
            $send_body['data']['remark']['color'] = "#FF0000";

            $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $g_AccessToken;
            $res = $jssdk->https_curl_json($url, $send_body, 'json');
            //修改订单状态
            $dosql->ExecNoneQuery("update  `#@__order` set jindu='4',manageid='$qiang_user_id' where id='$orderid' ");
            $dosql->ExecNoneQuery("insert into `#@__order_log`(orderid,op,op_time,jindu,manageid) values ('$orderid','系统智能分配工单','$post_time','4','$qiang_user_id')");
        }


    }
}


//========= 工作时执行 ============
// 列出系统中未接单的 工单
// 60分钟接单 （每60分钟提醒一次）  2小时后不接单扣除奖励
if ($h > 7 && $h < 19) {
    $sql_order_2 = "SELECT id,manageid,post_time,apply_device,content,school,truename,mobile  FROM  `#@__order`  where    jindu='3'   and is_delete=0 and manageid!=''   order by id desc   ";
    $dosql->Execute($sql_order_2);
    while ($row2 = $dosql->GetArray()) {

        $orderid = $row2['id'];
        echo "【接单超时】========单号" . $orderid . "=========<br>";
        $mids = $row2['manageid'];
        $orderidname = date('Ymd', $row2['post_time']) . "-" . $orderid;  //工单号
        $repairname = getRepairMode($row2['apply_device']);  //任务名称
        $task = $row2['apply_device'];  //任务名称
        $apply_time = date("Y-m-d H:i:s", $row2['post_time']);
        $content = $row2['content'];
        $school = $row2['school'];
        $truename = $row2['truename'];
        $mobile = $row2['mobile'];

        //查找 任务日志
        $row_order = $dosql->GetOne("SELECT *  FROM  `#@__order_log`  where orderid='$orderid'   AND jindu='3'  order by id desc   ");

        echo "【工单记录 start】========详情<br>";
        var_export($row_order);
        echo "<br>=========<br>";

        $last_time = $row_order['op_time'];

        echo "【工单日志记录】========工单日志最后一次操作时间 " . date("Y-m-d H:i:s", $last_time) . "=========<br>";

        //执行人
        $zhixingren = "";
        $ids_arr = explode(",", $mids);
        foreach ($ids_arr as $key => $val) {
            $zhixingren .= getManage($val) . "    ";
        }

        //消息推送
        if ($nowtime - $last_time > $cfg_jiedanouttime * 60) {
            echo "【工单记录】========id " . $orderid . "  已经超时未接单  ======<br>";
            //判断是否 推送消息
            $row_timeout = $dosql->GetOne("SELECT *  FROM  `#@__timeout_log`  where   orderid='$orderid'   AND  jindu='3' AND sendmsg='true' and `type`='order'  order by id desc   ");
            if (is_array($row_timeout) && isset($row_timeout['id'])) {


                $last_outtime = $row_timeout['op_time'];
                echo "【工单超时记录】========超时日志最后一次记录时间 " . date("Y-m-d H:i:s", $last_outtime) . "=========<br>";
                // 判断是否  再次 超过
                if ($post_time - $last_outtime > $cfg_jiedanouttime * 60) {
                    //再次超时 ，记录入库 并发送消息
                    foreach ($ids_arr as $key => $val) {
                        //获取工程师 openid
                        $m = $dosql->GetOne("select openid  from `#@__user`  where id='$val'");
                        $openid_str = $m['openid'];
                        //插入更新的状态
                        $dosql->ExecNoneQuery("insert into `#@__timeout_log`(orderid,op,op_time,jindu,manageid,sendmsg) values ('$orderid','工单未接单超时提醒','$post_time','3','$val','true')");

                        $send_body['touser'] = $openid_str;
                        $send_body['template_id'] = $cfg_ordertimeout;
                        $send_body['url'] = $cfg_weburl . 'wx/morderDetail.php?orderid=' . $orderid;
                        $send_body['data']['first']['value'] = "📢 您好，你有工单未接单请及时处理。";
                        $send_body['data']['first']['color'] = "#FF0000";
                        $send_body['data']['keyword1']['value'] = $orderidname;
                        $send_body['data']['keyword1']['color'] = "#173177";
                        $send_body['data']['keyword2']['value'] = $zhixingren;
                        $send_body['data']['keyword2']['color'] = "#FF0000";
                        $send_body['data']['keyword3']['value'] = "💗" . $school . " - " . $truename;
                        $send_body['data']['keyword3']['color'] = "#0e48cb";
                        $send_body['data']['keyword4']['value'] = $apply_time;
                        $send_body['data']['keyword4']['color'] = "#0e48cb";
                        $send_body['data']['keyword5']['value'] = $content;
                        $send_body['data']['keyword5']['color'] = "#0e48cb";
                        $send_body['data']['remark']['value'] = "👉请及时接单，每30分钟提醒一次！请点击接单。如 ".$cfg_jiedanouttime."分钟不接单，系统将再次扣除奖励。服务热线:" . $cfg_hotline . "👈";
                        $send_body['data']['remark']['color'] = "#FF0000";
                        $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $g_AccessToken;
                        $res = $jssdk->https_curl_json($url, $send_body, 'json');
                    }
                }
            } else {
                //首次超时 ，记录入库 并发送消息

                foreach ($ids_arr as $key => $val) {
                    //获取工程师 openid
                    $m = $dosql->GetOne("select `openid`  from `#@__user`  where id='$val'");
                    $openid_str = $m['openid'];
                    //插入更新的状态
                    $dosql->ExecNoneQuery("insert into `#@__timeout_log`(orderid,op,op_time,jindu,manageid,sendmsg,`type`,task) values ('$orderid','工单未接单超时提醒','$post_time','3','$val','true','order','$task')");


                    $send_body['touser'] = $openid_str;
                    $send_body['template_id'] = $cfg_ordertimeout;
                    $send_body['url'] = $cfg_weburl . 'wx/morderDetail.php?orderid=' . $orderid;
                    $send_body['data']['first']['value'] = "📢 您好，你有工单未接单请及时处理。";
                    $send_body['data']['first']['color'] = "#FF0000";
                    $send_body['data']['keyword1']['value'] = $orderidname;
                    $send_body['data']['keyword1']['color'] = "#173177";
                    $send_body['data']['keyword2']['value'] = $zhixingren;
                    $send_body['data']['keyword2']['color'] = "#FF0000";
                    $send_body['data']['keyword3']['value'] = "💗" . $school . " - " . $truename;
                    $send_body['data']['keyword3']['color'] = "#0e48cb";
                    $send_body['data']['keyword4']['value'] = $apply_time;
                    $send_body['data']['keyword4']['color'] = "#0e48cb";
                    $send_body['data']['keyword5']['value'] = $content;
                    $send_body['data']['keyword5']['color'] = "#0e48cb";
                    $send_body['data']['remark']['value'] = "👉请及时接单，每".$cfg_jiedanouttime."分钟提醒一次！请点击接单。如".$cfg_jiedanouttime." 分钟不接单，系统将再次扣除奖励。服务热线:" . $cfg_hotline . "👈";
                    $send_body['data']['remark']['color'] = "#FF0000";
                    $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $g_AccessToken;
                    $res = $jssdk->https_curl_json($url, $send_body, 'json');
                }
            }


            // 扣除奖励
            if ($post_time - $last_time > $cfg_jiedanouttime * 60) {
                //判断是否 推送消息
                $row_fee = $dosql->GetOne("SELECT *  FROM  `#@__fee_log`  where   orderid='$orderid'   AND jindu='3'  AND op='move'  order by id desc   ");
                if (is_array($row_fee) && isset($row_fee['id'])) {
                    $last_feetime = $row_fee['op_time'];
                    // 判断是否  再次 超过
                    if ($post_time - $last_feetime > $cfg_jiedanouttime * 60) {
                        //再次超时 ，记录入库 并发送消息
                        foreach ($ids_arr as $key => $val) {
                            //获取工程师 openid
                            $m = $dosql->GetOne("select `openid`  from `#@__user`  where id='$val'");
                            $openid_str = $m['openid'];
                            //插入更新的状态
                            $dosql->ExecNoneQuery("insert into `#@__fee_log`(orderid,op,op_time,jindu,manageid,fee,remark,`type`,task,feetype) values ('$orderid','move','$post_time','3','$val','$cfg_jiedanoutfee','工单超时没有接单，再次扣除奖励','order','$task','jiedanchaoshi')");
                            //推送超时提醒

                        }
                    }
                } else {
                    //首次超时 ，记录入库 并发送消息
                    foreach ($ids_arr as $key => $val) {
                        //获取工程师 openid
                        $m = $dosql->GetOne("select `openid`  from `#@__user`  where id='$val'");
                        $openid_str = $m['openid'];
                        $remark='工单'.$cfg_jiedanouttime.'分钟没有接单，扣除奖励';
                        //插入更新的状态
                        $dosql->ExecNoneQuery("insert into `#@__fee_log`(orderid,op,op_time,jindu,manageid,fee,remark,`type`,task,feetype) values ('$orderid','move','$post_time','3','$val','$cfg_jiedanoutfee','$remark','order','$task','jiedanchaoshi')");
                    }
                }

            }

        }

        echo "【工单记录 end 】===========================<br><br><br>";
    }

}


//========= 工作时执行 ============
// 列出系统中 接单未签到 任务
// 先签到再完成或者反馈  接单2小时后签到
if ($h > 7 && $h < 19) {


    $sql_order = "SELECT id,manageid,post_time,apply_device,content,school,truename,mobile  FROM  `#@__order`  where    jindu='4'   and is_delete=0  and qiandao=''  order by id desc   ";
    $dosql->Execute($sql_order);
    while ($row = $dosql->GetArray()) {
        $orderid = $row['id'];
        echo "id: ".$orderid."  未签到<br>";
        $mids = $row['manageid'];
        $content = $row['content'];
        $orderidname = date('Ymd', $row['post_time']) . "-" . $orderid;  //工单号
        $repairname = getRepairMode($row['apply_device']);  //任务名称
        $task = $row['apply_device'];  //任务名称
        $apply_time = date("Y-m-d H:i:s", $row['post_time']);
        $school = $row['school'];
        $truename = $row['truename'];
        $mobile = $row['mobile'];
        //执行人
        $zhixingren = "";
        $ids_arr = explode(",", $mids);
        foreach ($ids_arr as $key => $val) {
            $zhixingren .= getManage($val) . "    ";
        }
        //查找 接单 日志
        // 如果存在反馈的信息，则不执行
        $row_order = $dosql->GetOne("SELECT *  FROM  `#@__order_log`  where   orderid='$orderid'   AND jindu='4'   order by id desc   ");
        $last_time = $row_order['op_time'];
        $is_fankui = $row_order['fankui'];



        //接单后需要签到的
        //消息推送
        if ( time() - $last_time > $cfg_doingouttime * 60 && $is_fankui == '') {
            echo "id: ".$orderid."  未签到 未推送<br>";
            //判断是否 推送消息
            $row_timeout = $dosql->GetOne("SELECT *  FROM  `#@__timeout_log`  where   orderid='$orderid'   AND   jindu='4' AND  sendmsg='true' and `type`='order' order by id desc   ");
            if (is_array($row_timeout) && isset($row_timeout['id'])) {
                $last_outtime = $row_timeout['op_time'];
                // 判断是否  再次 超过
                if ($post_time - $last_outtime > $cfg_doingouttime * 60) {
                    //再次超时 ，记录入库 并发送消息
                    foreach ($ids_arr as $key => $val) {
                        //获取工程师 openid
                        $m = $dosql->GetOne("select openid  from `#@__user`  where id='$val'");
                        $openid_str = $m['openid'];
                        //插入更新的状态
                        $dosql->ExecNoneQuery("insert into `#@__timeout_log`(orderid,op,op_time,jindu,manageid,sendmsg,`type`,task) values ('$orderid','工单超时提醒','$post_time','4','$val','true','order','$task')");


                        $send_body['touser'] = $openid_str;
                        $send_body['template_id'] = $cfg_ordertimeout;
                        $send_body['url'] = $cfg_weburl . 'wx/morderDetail.php?orderid=' . $orderid;
                        $send_body['data']['first']['value'] = "📢 接单后" . ($cfg_doingouttime / 60) . "个小时没有签到或者反馈，再次超时。您好，接单后请及时签到和处理。";
                        $send_body['data']['first']['color'] = "#FF0000";
                        $send_body['data']['keyword1']['value'] = $orderidname;
                        $send_body['data']['keyword1']['color'] = "#173177";
                        $send_body['data']['keyword2']['value'] = $zhixingren;
                        $send_body['data']['keyword2']['color'] = "#FF0000";
                        $send_body['data']['keyword3']['value'] = "💗" . $school . " - " . $truename;
                        $send_body['data']['keyword3']['color'] = "#0e48cb";
                        $send_body['data']['keyword4']['value'] = $apply_time;
                        $send_body['data']['keyword4']['color'] = "#0e48cb";
                        $send_body['data']['keyword5']['value'] = $content;
                        $send_body['data']['keyword5']['color'] = "#0e48cb";
                        $send_body['data']['remark']['value'] = "👉 请点击签到或者反馈。如60分钟后不接单，系统将扣除奖励。服务热线:" . $cfg_hotline . "👈";
                        $send_body['data']['remark']['color'] = "#FF0000";
                        $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $g_AccessToken;
                        $res = $jssdk->https_curl_json($url, $send_body, 'json');


                    }
                }
            } else {
                //首次超时 ，记录入库 并发送消息
                foreach ($ids_arr as $key => $val) {
                    //获取工程师 openid
                    if ($val > 0) {

                        $m = $dosql->GetOne("select openid  from `#@__user`  where id='$val'");
                        $openid_str = $m['openid'];
                        //插入更新的状态
                        $dosql->ExecNoneQuery("insert into `#@__timeout_log`(orderid,op,op_time,jindu,manageid,sendmsg,`type`,task) values ('$orderid','工单超时提醒','$post_time','4','$val','true','order','$task')");

                        $send_body['touser'] = $openid_str;
                        $send_body['template_id'] = $cfg_ordertimeout;
                        $send_body['url'] = $cfg_weburl . 'wx/morderDetail.php?orderid=' . $orderid;
                        $send_body['data']['first']['value'] = "📢 接单后" . ($cfg_doingouttime / 60) . "个小时没有签到或者反馈，首次提醒。您好，接单后请及时签到或者反馈。";
                        $send_body['data']['first']['color'] = "#FF0000";
                        $send_body['data']['keyword1']['value'] = $orderidname;
                        $send_body['data']['keyword1']['color'] = "#173177";
                        $send_body['data']['keyword2']['value'] = $zhixingren;
                        $send_body['data']['keyword2']['color'] = "#FF0000";
                        $send_body['data']['keyword3']['value'] = "💗" . $school . " - " . $truename;
                        $send_body['data']['keyword3']['color'] = "#0e48cb";
                        $send_body['data']['keyword4']['value'] = $apply_time;
                        $send_body['data']['keyword4']['color'] = "#0e48cb";
                        $send_body['data']['keyword5']['value'] = $content;
                        $send_body['data']['keyword5']['color'] = "#0e48cb";
                        $send_body['data']['remark']['value'] = "👉 请点击签到或者反馈。如60分钟后没有签到或者反馈，系统将扣除奖励。服务热线:" . $cfg_hotline . "👈";
                        $send_body['data']['remark']['color'] = "#FF0000";
                        $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $g_AccessToken;
                        $res = $jssdk->https_curl_json($url, $send_body, 'json');
                    }
                }
            }

            // 扣除奖励
            if ($post_time - $last_time > $cfg_doingouttime * 60 + 3600) {
                //判断是否 推送消息
                $row_fee = $dosql->GetOne("SELECT *  FROM  `#@__fee_log`  where   orderid='$orderid'  AND jindu='4'  AND op='move'  order by id desc   ");
                if (is_array($row_fee) && isset($row_fee['id'])) {
                    $last_feetime = $row_fee['op_time'];
                    // 判断是否  再次 超过
                    if ($post_time - $last_feetime > $cfg_doingouttime * 60 + 3600) {
                        //再次超时 ，记录入库 并发送消息
                        foreach ($ids_arr as $key => $val) {
                            //获取工程师 openid
                            $m = $dosql->GetOne("select openid  from `#@__user`  where id='$val'");
                            $openid_str = $m['openid'];
                            //插入更新的状态
                            $dosql->ExecNoneQuery("insert into `#@__fee_log`(orderid,op,op_time,jindu,manageid,fee,remark,`type`,`task`,feetype) values ('$orderid','move','$post_time','4','$val','$cfg_doingoutfee','工单超时没有接单，再次扣除奖励$cfg_doingoutfee','order','$task','jiedanchaoshi')");
                            //推送超时提醒

                        }
                    }
                } else {
                    //首次超时 ，记录入库 并发送消息
                    foreach ($ids_arr as $key => $val) {
                        //获取工程师 openid
                        $m = $dosql->GetOne("select openid  from `#@__user`  where id='$val'");
                        $openid_str = $m['openid'];
                        //插入更新的状态
                        $dosql->ExecNoneQuery("insert into `#@__fee_log`(orderid,op,op_time,jindu,manageid,fee,remark,`type`,`task`,feetype) values ('$orderid','move','$post_time','4','$val','$cfg_doingoutfee','工单超时没有接单，扣除奖励$cfg_doingoutfee','order','$task','jiedanchaoshi')");
                    }
                }

            }

        }

        //接单后  反馈  然后  第二天需要重新签到的
        //消息推送
        $last_time_d = date("d", $last_time);
        if ($last_time_d != $d && $is_fankui == 'true') {
            //判断是否 推送消息
            $row_timeout = $dosql->GetOne("SELECT *  FROM  `#@__timeout_log`  where   orderid='$orderid'   AND   jindu='4' AND  sendmsg='true' and `type`='order' order by id desc   ");
            if (is_array($row_timeout) && isset($row_timeout['id'])) {
                $last_outtime = $row_timeout['op_time'];
                // 判断是否  再次 超过
                if ($post_time - $last_outtime > 3600) {
                    //再次超时 ，记录入库 并发送消息
                    foreach ($ids_arr as $key => $val) {
                        //获取工程师 openid
                        $m = $dosql->GetOne("select openid  from `#@__user`  where id='$val'");
                        $openid_str = $m['openid'];
                        //插入更新的状态
                        $dosql->ExecNoneQuery("insert into `#@__timeout_log`(orderid,op,op_time,jindu,manageid,sendmsg,`type`,`task`) values ('$orderid','反馈工单次日再次超时提醒','$post_time','4','$val','true','order','$task')");


                        $send_body['touser'] = $openid_str;
                        $send_body['template_id'] = $cfg_ordertimeout;
                        $send_body['url'] = $cfg_weburl . 'wx/morderDetail.php?orderid=' . $orderid;
                        $send_body['data']['first']['value'] = "📢 您好，昨日反馈工单请及时签到或反馈。再次提醒";
                        $send_body['data']['first']['color'] = "#FF0000";
                        $send_body['data']['keyword1']['value'] = $orderidname;
                        $send_body['data']['keyword1']['color'] = "#173177";
                        $send_body['data']['keyword2']['value'] = $zhixingren;
                        $send_body['data']['keyword2']['color'] = "#FF0000";
                        $send_body['data']['keyword3']['value'] = "💗" . $school . " - " . $truename;
                        $send_body['data']['keyword3']['color'] = "#0e48cb";
                        $send_body['data']['keyword4']['value'] = $apply_time;
                        $send_body['data']['keyword4']['color'] = "#0e48cb";
                        $send_body['data']['keyword5']['value'] = $content;
                        $send_body['data']['keyword5']['color'] = "#0e48cb";
                        $send_body['data']['remark']['value'] = "👉 请点击签到或者反馈。如90分钟后不处理，系统将扣除奖励.服务热线:" . $cfg_hotline . "👈";
                        $send_body['data']['remark']['color'] = "#FF0000";
                        $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $g_AccessToken;
                        $res = $jssdk->https_curl_json($url, $send_body, 'json');
                    }
                }
            } else {
                //首次超时 ，记录入库 并发送消息
                foreach ($ids_arr as $key => $val) {
                    //获取工程师 openid
                    $m = $dosql->GetOne("select openid  from `#@__user`  where id='$val'");
                    $openid_str = $m['openid'];
                    //插入更新的状态
                    $dosql->ExecNoneQuery("insert into `#@__timeout_log`(orderid,op,op_time,jindu,manageid,sendmsg) values ('$orderid','反馈工单次日超时提醒','$post_time','4','$val','true')");


                    $send_body['touser'] = $openid_str;
                    $send_body['template_id'] = $cfg_ordertimeout;
                    $send_body['url'] = $cfg_weburl . 'wx/morderDetail.php?orderid=' . $orderid;
                    $send_body['data']['first']['value'] = "📢 您好，昨日反馈工单请及时签到或反馈。首次提醒";
                    $send_body['data']['first']['color'] = "#FF0000";
                    $send_body['data']['keyword1']['value'] = $orderidname;
                    $send_body['data']['keyword1']['color'] = "#173177";
                    $send_body['data']['keyword2']['value'] = $zhixingren;
                    $send_body['data']['keyword2']['color'] = "#FF0000";
                    $send_body['data']['keyword3']['value'] = "💗" . $school . " - " . $truename;
                    $send_body['data']['keyword3']['color'] = "#0e48cb";
                    $send_body['data']['keyword4']['value'] = $apply_time;
                    $send_body['data']['keyword4']['color'] = "#0e48cb";
                    $send_body['data']['keyword5']['value'] = $content;
                    $send_body['data']['keyword5']['color'] = "#0e48cb";
                    $send_body['data']['remark']['value'] = "👉请点击签到或者反馈。如90分钟后不处理，系统将扣除奖励.服务热线:" . $cfg_hotline . "👈";
                    $send_body['data']['remark']['color'] = "#FF0000";
                    $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $g_AccessToken;
                    $res = $jssdk->https_curl_json($url, $send_body, 'json');

                }
            }

            // 扣除奖励
            // 上班时间
            $workToday = mktime(8, 00, 0, date('m'), date('d'), date('Y'));  //今日上班开始时间
            if ($post_time - $workToday > 5400) {
                //判断是否 推送消息
                $row_fee = $dosql->GetOne("SELECT *  FROM  `#@__fee_log`  where   orderid='$orderid'  AND jindu='4'  AND op='move'  order by id desc   ");
                if (is_array($row_fee) && isset($row_fee['id'])) {
                    $last_feetime = $row_fee['op_time'];
                    // 判断是否  再次 超过
                    if ($post_time - $last_feetime > 5400) {
                        //再次超时 ，记录入库 并发送消息
                        foreach ($ids_arr as $key => $val) {
                            //获取工程师 openid
                            $m = $dosql->GetOne("select openid  from `#@__user`  where id='$val'");
                            $openid_str = $m['openid'];
                            //插入更新的状态
                            $dosql->ExecNoneQuery("insert into `#@__fee_log`(orderid,op,op_time,jindu,manageid,fee,remark,`type`,task,feetype) values ('$orderid','move','$post_time','4','$val','1','反馈工单次日未签到或反馈，再次扣除奖励'.$cfg_ciriout.'。','order','$task','jiedanchaoshi')");
                            //推送超时提醒

                        }
                    }
                } else {
                    //首次超时 ，记录入库 并发送消息
                    foreach ($ids_arr as $key => $val) {
                        //获取工程师 openid
                        $m = $dosql->GetOne("select openid  from `#@__user`  where id='$val'");
                        $openid_str = $m['openid'];
                        //插入更新的状态
                        $dosql->ExecNoneQuery("insert into `#@__fee_log`(orderid,op,op_time,jindu,manageid,fee,remark,`type`,task,feetype) values ('$orderid','move','$post_time','4','$val','$cfg_ciriout','反馈工单次日未签到或反馈，扣除奖励'.$cfg_ciriout.'。','order','$task','jiedanchaoshi')");
                    }
                }

            }

        }
    }
}


//========= 工作时执行 ============
// 列出系统中 24小时没有反馈的 任务
// 先签到再完成或者反馈  接单2小时后签到
if ($h > 7 && $h < 19) {


    $sql_order = "SELECT id,manageid,post_time,apply_device,content,school,truename,mobile  FROM  `#@__order`  where    jindu='4'   and is_delete=0     order by id desc   ";
    $dosql->Execute($sql_order);
    while ($row = $dosql->GetArray()) {
        $orderid = $row['id'];
        echo "id: ".$orderid."  处理中的工单<br>";
        $mids = $row['manageid'];
        $content = $row['content'];
        $orderidname = date('Ymd', $row['post_time']) . "-" . $orderid;  //工单号
        $repairname = getRepairMode($row['apply_device']);  //任务名称
        $task = $row['apply_device'];  //任务名称
        $apply_time = date("Y-m-d H:i:s", $row['post_time']);
        $school = $row['school'];
        $truename = $row['truename'];
        $mobile = $row['mobile'];
        //执行人
        $zhixingren = "";
        $ids_arr = explode(",", $mids);
        foreach ($ids_arr as $key => $val) {
            $zhixingren .= getManage($val) . "    ";
        }
        //查找 接单 日志
        // 如果存在反馈的信息，则不执行
        $row_order = $dosql->GetOne("SELECT *  FROM  `#@__order_log`  where   orderid='$orderid'   AND jindu='4'   order by id desc   ");
        $last_time = $row_order['op_time'];
        $is_fankui = $row_order['fankui'];



        //接单后需要签到的
        //消息推送
        if ( time() - $last_time > 86400 && $is_fankui != '') {
            echo "id: ".$orderid."  反馈后 24小时没有进展的<br>";
            //判断是否 推送消息
            $row_timeout = $dosql->GetOne("SELECT *  FROM  `#@__timeout_log`  where   orderid='$orderid'   AND   jindu='4' AND  sendmsg='true' and `type`='fankui' order by id desc   ");
            if (is_array($row_timeout) && isset($row_timeout['id'])) {
                $last_outtime = $row_timeout['op_time'];
                // 判断是否  再次 超过
                if ($post_time - $last_outtime > $cfg_doingouttime * 60) {
                    //再次超时 ，记录入库 并发送消息
                    foreach ($ids_arr as $key => $val) {
                        //获取工程师 openid
                        $m = $dosql->GetOne("select openid  from `#@__user`  where id='$val'");
                        $openid_str = $m['openid'];
                        //插入更新的状态
                        $dosql->ExecNoneQuery("insert into `#@__timeout_log`(orderid,op,op_time,jindu,manageid,sendmsg,`type`,task) values ('$orderid','工单反馈后24小时没有进展超时提醒','$post_time','4','$val','true','order','$task')");


                        $send_body['touser'] = $openid_str;
                        $send_body['template_id'] = $cfg_ordertimeout;
                        $send_body['url'] = $cfg_weburl . 'wx/morderDetail.php?orderid=' . $orderid;
                        $send_body['data']['first']['value'] = "📢 接单后" . ($cfg_doingouttime / 60) . "个小时没有签到或者反馈，再次超时。您好，接单后请及时签到和处理。";
                        $send_body['data']['first']['color'] = "#FF0000";
                        $send_body['data']['keyword1']['value'] = $orderidname;
                        $send_body['data']['keyword1']['color'] = "#173177";
                        $send_body['data']['keyword2']['value'] = $zhixingren;
                        $send_body['data']['keyword2']['color'] = "#FF0000";
                        $send_body['data']['keyword3']['value'] = "💗" . $school . " - " . $truename;
                        $send_body['data']['keyword3']['color'] = "#0e48cb";
                        $send_body['data']['keyword4']['value'] = $apply_time;
                        $send_body['data']['keyword4']['color'] = "#0e48cb";
                        $send_body['data']['keyword5']['value'] = $content;
                        $send_body['data']['keyword5']['color'] = "#0e48cb";
                        $send_body['data']['remark']['value'] = "👉 请点击签到或者反馈。如60分钟后不接单，系统将扣除奖励。服务热线:" . $cfg_hotline . "👈";
                        $send_body['data']['remark']['color'] = "#FF0000";
                        $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $g_AccessToken;
                        $res = $jssdk->https_curl_json($url, $send_body, 'json');


                    }
                }
            } else {
                //首次超时 ，记录入库 并发送消息
                foreach ($ids_arr as $key => $val) {
                    //获取工程师 openid
                    if ($val > 0) {

                        $m = $dosql->GetOne("select openid  from `#@__user`  where id='$val'");
                        $openid_str = $m['openid'];
                        //插入更新的状态
                        $dosql->ExecNoneQuery("insert into `#@__timeout_log`(orderid,op,op_time,jindu,manageid,sendmsg,`type`,task) values ('$orderid','工单超时提醒','$post_time','4','$val','true','order','$task')");

                        $send_body['touser'] = $openid_str;
                        $send_body['template_id'] = $cfg_ordertimeout;
                        $send_body['url'] = $cfg_weburl . 'wx/morderDetail.php?orderid=' . $orderid;
                        $send_body['data']['first']['value'] = "📢 接单后" . ($cfg_doingouttime / 60) . "个小时没有签到或者反馈，首次提醒。您好，接单后请及时签到或者反馈。";
                        $send_body['data']['first']['color'] = "#FF0000";
                        $send_body['data']['keyword1']['value'] = $orderidname;
                        $send_body['data']['keyword1']['color'] = "#173177";
                        $send_body['data']['keyword2']['value'] = $zhixingren;
                        $send_body['data']['keyword2']['color'] = "#FF0000";
                        $send_body['data']['keyword3']['value'] = "💗" . $school . " - " . $truename;
                        $send_body['data']['keyword3']['color'] = "#0e48cb";
                        $send_body['data']['keyword4']['value'] = $apply_time;
                        $send_body['data']['keyword4']['color'] = "#0e48cb";
                        $send_body['data']['keyword5']['value'] = $content;
                        $send_body['data']['keyword5']['color'] = "#0e48cb";
                        $send_body['data']['remark']['value'] = "👉 请点击签到或者反馈。如60分钟后没有签到或者反馈，系统将扣除奖励。服务热线:" . $cfg_hotline . "👈";
                        $send_body['data']['remark']['color'] = "#FF0000";
                        $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $g_AccessToken;
                        $res = $jssdk->https_curl_json($url, $send_body, 'json');
                    }
                }
            }

            // 扣除奖励
            if ($post_time - $last_time > $cfg_doingouttime * 60 + 3600) {
                //判断是否 推送消息
                $row_fee = $dosql->GetOne("SELECT *  FROM  `#@__fee_log`  where   orderid='$orderid'  AND jindu='4'  AND op='move'  order by id desc   ");
                if (is_array($row_fee) && isset($row_fee['id'])) {
                    $last_feetime = $row_fee['op_time'];
                    // 判断是否  再次 超过
                    if ($post_time - $last_feetime > $cfg_doingouttime * 60 + 3600) {
                        //再次超时 ，记录入库 并发送消息
                        foreach ($ids_arr as $key => $val) {
                            //获取工程师 openid
                            $m = $dosql->GetOne("select openid  from `#@__user`  where id='$val'");
                            $openid_str = $m['openid'];
                            //插入更新的状态
                            $dosql->ExecNoneQuery("insert into `#@__fee_log`(orderid,op,op_time,jindu,manageid,fee,remark,`type`,`task`,feetype) values ('$orderid','move','$post_time','4','$val','$cfg_doingoutfee','工单超时没有接单，再次扣除奖励$cfg_doingoutfee','order','$task','jiedanchaoshi')");
                            //推送超时提醒

                        }
                    }
                } else {
                    //首次超时 ，记录入库 并发送消息
                    foreach ($ids_arr as $key => $val) {
                        //获取工程师 openid
                        $m = $dosql->GetOne("select openid  from `#@__user`  where id='$val'");
                        $openid_str = $m['openid'];
                        //插入更新的状态
                        $dosql->ExecNoneQuery("insert into `#@__fee_log`(orderid,op,op_time,jindu,manageid,fee,remark,`type`,`task`,feetype) values ('$orderid','move','$post_time','4','$val','$cfg_doingoutfee','工单超时没有接单，扣除奖励$cfg_doingoutfee','order','$task','jiedanchaoshi')");
                    }
                }

            }

        }

        //接单后  反馈  然后  第二天需要重新签到的
        //消息推送
        $last_time_d = date("d", $last_time);
        if ($last_time_d != $d && $is_fankui == 'true') {
            //判断是否 推送消息
            $row_timeout = $dosql->GetOne("SELECT *  FROM  `#@__timeout_log`  where   orderid='$orderid'   AND   jindu='4' AND  sendmsg='true' and `type`='order' order by id desc   ");
            if (is_array($row_timeout) && isset($row_timeout['id'])) {
                $last_outtime = $row_timeout['op_time'];
                // 判断是否  再次 超过
                if ($post_time - $last_outtime > 3600) {
                    //再次超时 ，记录入库 并发送消息
                    foreach ($ids_arr as $key => $val) {
                        //获取工程师 openid
                        $m = $dosql->GetOne("select openid  from `#@__user`  where id='$val'");
                        $openid_str = $m['openid'];
                        //插入更新的状态
                        $dosql->ExecNoneQuery("insert into `#@__timeout_log`(orderid,op,op_time,jindu,manageid,sendmsg,`type`,`task`) values ('$orderid','反馈工单次日再次超时提醒','$post_time','4','$val','true','order','$task')");


                        $send_body['touser'] = $openid_str;
                        $send_body['template_id'] = $cfg_ordertimeout;
                        $send_body['url'] = $cfg_weburl . 'wx/morderDetail.php?orderid=' . $orderid;
                        $send_body['data']['first']['value'] = "📢 您好，昨日反馈工单请及时签到或反馈。再次提醒";
                        $send_body['data']['first']['color'] = "#FF0000";
                        $send_body['data']['keyword1']['value'] = $orderidname;
                        $send_body['data']['keyword1']['color'] = "#173177";
                        $send_body['data']['keyword2']['value'] = $zhixingren;
                        $send_body['data']['keyword2']['color'] = "#FF0000";
                        $send_body['data']['keyword3']['value'] = "💗" . $school . " - " . $truename;
                        $send_body['data']['keyword3']['color'] = "#0e48cb";
                        $send_body['data']['keyword4']['value'] = $apply_time;
                        $send_body['data']['keyword4']['color'] = "#0e48cb";
                        $send_body['data']['keyword5']['value'] = $content;
                        $send_body['data']['keyword5']['color'] = "#0e48cb";
                        $send_body['data']['remark']['value'] = "👉 请点击签到或者反馈。如90分钟后不处理，系统将扣除奖励.服务热线:" . $cfg_hotline . "👈";
                        $send_body['data']['remark']['color'] = "#FF0000";
                        $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $g_AccessToken;
                        $res = $jssdk->https_curl_json($url, $send_body, 'json');
                    }
                }
            } else {
                //首次超时 ，记录入库 并发送消息
                foreach ($ids_arr as $key => $val) {
                    //获取工程师 openid
                    $m = $dosql->GetOne("select openid  from `#@__user`  where id='$val'");
                    $openid_str = $m['openid'];
                    //插入更新的状态
                    $dosql->ExecNoneQuery("insert into `#@__timeout_log`(orderid,op,op_time,jindu,manageid,sendmsg) values ('$orderid','反馈工单次日超时提醒','$post_time','4','$val','true')");


                    $send_body['touser'] = $openid_str;
                    $send_body['template_id'] = $cfg_ordertimeout;
                    $send_body['url'] = $cfg_weburl . 'wx/morderDetail.php?orderid=' . $orderid;
                    $send_body['data']['first']['value'] = "📢 您好，昨日反馈工单请及时签到或反馈。首次提醒";
                    $send_body['data']['first']['color'] = "#FF0000";
                    $send_body['data']['keyword1']['value'] = $orderidname;
                    $send_body['data']['keyword1']['color'] = "#173177";
                    $send_body['data']['keyword2']['value'] = $zhixingren;
                    $send_body['data']['keyword2']['color'] = "#FF0000";
                    $send_body['data']['keyword3']['value'] = "💗" . $school . " - " . $truename;
                    $send_body['data']['keyword3']['color'] = "#0e48cb";
                    $send_body['data']['keyword4']['value'] = $apply_time;
                    $send_body['data']['keyword4']['color'] = "#0e48cb";
                    $send_body['data']['keyword5']['value'] = $content;
                    $send_body['data']['keyword5']['color'] = "#0e48cb";
                    $send_body['data']['remark']['value'] = "👉请点击签到或者反馈。如90分钟后不处理，系统将扣除奖励.服务热线:" . $cfg_hotline . "👈";
                    $send_body['data']['remark']['color'] = "#FF0000";
                    $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $g_AccessToken;
                    $res = $jssdk->https_curl_json($url, $send_body, 'json');

                }
            }

            // 扣除奖励
            // 上班时间
            $workToday = mktime(8, 00, 0, date('m'), date('d'), date('Y'));  //今日上班开始时间
            if ($post_time - $workToday > 5400) {
                //判断是否 推送消息
                $row_fee = $dosql->GetOne("SELECT *  FROM  `#@__fee_log`  where   orderid='$orderid'  AND jindu='4'  AND op='move'  order by id desc   ");
                if (is_array($row_fee) && isset($row_fee['id'])) {
                    $last_feetime = $row_fee['op_time'];
                    // 判断是否  再次 超过
                    if ($post_time - $last_feetime > 5400) {
                        //再次超时 ，记录入库 并发送消息
                        foreach ($ids_arr as $key => $val) {
                            //获取工程师 openid
                            $m = $dosql->GetOne("select openid  from `#@__user`  where id='$val'");
                            $openid_str = $m['openid'];
                            //插入更新的状态
                            $dosql->ExecNoneQuery("insert into `#@__fee_log`(orderid,op,op_time,jindu,manageid,fee,remark,`type`,task,feetype) values ('$orderid','move','$post_time','4','$val','1','反馈工单次日未签到或反馈，再次扣除奖励'.$cfg_ciriout.'。','order','$task','jiedanchaoshi')");
                            //推送超时提醒

                        }
                    }
                } else {
                    //首次超时 ，记录入库 并发送消息
                    foreach ($ids_arr as $key => $val) {
                        //获取工程师 openid
                        $m = $dosql->GetOne("select openid  from `#@__user`  where id='$val'");
                        $openid_str = $m['openid'];
                        //插入更新的状态
                        $dosql->ExecNoneQuery("insert into `#@__fee_log`(orderid,op,op_time,jindu,manageid,fee,remark,`type`,task,feetype) values ('$orderid','move','$post_time','4','$val','$cfg_ciriout','反馈工单次日未签到或反馈，扣除奖励'.$cfg_ciriout.'。','order','$task','jiedanchaoshi')");
                    }
                }

            }

        }
    }
}



//========= 下班执行  ============
// 列出系统中 签到后 未处理的数据

$beginToday = mktime(7, 30, 0, date('m'), date('d'), date('Y'));  //下班开始时间
$endToday = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')) - 1; //今天的结束时间
if ($post_time > $beginToday && $post_time < $endToday   ) {
    echo "下班执行开始<br>";

    $sql_order_2 = "SELECT id,manageid,post_time,apply_device  FROM  `#@__order`  where    jindu='4'   and  is_delete='0'  and qiandao='true'  order by id desc   ";
    $dosql->Execute($sql_order_2);
    while ($row2 = $dosql->GetArray()) {




        $orderid = $row2['id'];
        echo "id: ".$orderid."  签到后未反馈的<br>";

        $order_post_time = $row2['post_time'];


        $mids = $row2['manageid'];
        $orderidname = date('Ymd', $row2['post_time']) . "-" . $orderid;  //工单号
        $repairname = getRepairMode($row2['apply_device']);  //任务名称
        $task_id = $row2['apply_device'];  //任务名称
        $apply_time = date("Y-m-d H:i:s", $row2['post_time']);

        //查找 任务日志
        $row_order = $dosql->GetOne("SELECT *  FROM  `#@__order_log`  where   orderid='$orderid'   AND jindu='4'   order by id desc   ");
        if (is_array($row_order) && $row_order['qiandao'] == 'true' && $order_post_time< $beginToday ) {
            $last_time = $row_order['op_time'];


            echo $orderid . "=============<br>";

            //执行人
            $zhixingren = "";
            $ids_arr = explode(",", $mids);
            foreach ($ids_arr as $key => $val) {
                $zhixingren .= getManage($val) . "    ";
            }

            //消息推送
            //判断是否 推送消息
            $row_timeout = $dosql->GetOne("SELECT *  FROM  `#@__timeout_log`  where   orderid='$orderid'   AND  jindu='4' AND sendmsg='true'  AND qiandao='1' order by id desc   ");
            var_dump($row_timeout);
            if (is_array($row_timeout) && isset($row_timeout['id'])) {
                $last_outtime = $row_timeout['op_time'];
                // 判断是否  再次 超过
                if ($post_time - $last_outtime > $cfg_doingouttime * 60) {

                    echo $orderid . "======== 再次超时 =====<br>";

                    //再次超时 ，记录入库 并发送消息
                   /* foreach ($ids_arr as $key => $val) {
                        //获取工程师 openid
                        $m = $dosql->GetOne("select openid  from `#@__user`  where id='$val'");
                        $openid_str = $m['openid'];
                        //插入更新的状态
                        $dosql->ExecNoneQuery("insert into `#@__timeout_log`(orderid,op,op_time,jindu,manageid,sendmsg,qiandao,task) values ('$orderid','下班签到工单未处理，再次提醒','$post_time','4','$val','true','1','$task_id')");


                        $send_body['touser'] = $openid_str;
                        $send_body['template_id'] = $cfg_order_status;
                        $send_body['url'] = $cfg_weburl . 'wx/morderDetail.php?orderid=' . $orderid;
                        $send_body['data']['first']['value'] = "📢 您好，辛苦一天下班了，你有工单还没有完成或反馈。";
                        $send_body['data']['first']['color'] = "#FF0000";
                        $send_body['data']['keyword1']['value'] = $orderidname;
                        $send_body['data']['keyword1']['color'] = "#173177";
                        $send_body['data']['keyword2']['value'] = $apply_time;
                        $send_body['data']['keyword2']['color'] = "#FF0000";
                        $send_body['data']['keyword3']['value'] = $zhixingren;
                        $send_body['data']['keyword3']['color'] = "#FF0000";
                        $send_body['data']['keyword4']['value'] = $repairname;
                        $send_body['data']['keyword4']['color'] = "#0e48cb";
                        $send_body['data']['keyword5']['value'] = "如任务结束请进行完修申报，如未结束请及时反馈。";
                        $send_body['data']['keyword5']['color'] = "#0e48cb";
                        $send_body['data']['remark']['value'] = "请点击处理。如'.$cfg_doingouttime.'分钟后未处理，系统将再次扣除奖励'.$cfg_doingoutfee.'。服务热线：'.$cfg_hotline.'";
                        $send_body['data']['remark']['color'] = "#FF0000";
                        $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $g_AccessToken;
                        $res = $jssdk->https_curl_json($url, $send_body, 'json');


                    }*/
                }
            } else {
                //首次超时 ，记录入库 并发送消息

                echo $orderid . "========首次超时=====<br>";

                /*foreach ($ids_arr as $key => $val) {
                    //获取工程师 openid
                    $m = $dosql->GetOne("select openid  from `#@__user`  where id='$val'");
                    $openid_str = $m['openid'];
                    //插入更新的状态
                    $dosql->ExecNoneQuery("insert into `#@__timeout_log`(orderid,op,op_time,jindu,manageid,sendmsg,qiandao,task) values ('$orderid','下班后签到工单未处理，首次提示','$post_time','4','$val','true','1','$task_id')");

                    $send_body['touser'] = $openid_str;
                    $send_body['template_id'] = $cfg_order_status;
                    $send_body['url'] = $cfg_weburl . 'wx/morderDetail.php?orderid=' . $orderid;
                    $send_body['data']['first']['value'] = "📢 您好，辛苦一天下班了，你有工单还没有完成或反馈。";
                    $send_body['data']['first']['color'] = "#FF0000";
                    $send_body['data']['keyword1']['value'] = $orderidname;
                    $send_body['data']['keyword1']['color'] = "#173177";
                    $send_body['data']['keyword2']['value'] = $apply_time;
                    $send_body['data']['keyword2']['color'] = "#FF0000";
                    $send_body['data']['keyword3']['value'] = $zhixingren;
                    $send_body['data']['keyword3']['color'] = "#FF0000";
                    $send_body['data']['keyword4']['value'] = $repairname;
                    $send_body['data']['keyword4']['color'] = "#0e48cb";
                    $send_body['data']['keyword5']['value'] = "如任务结束请进行完修申报，如未结束请及时反馈。";
                    $send_body['data']['keyword5']['color'] = "#0e48cb";
                    $send_body['data']['remark']['value'] = "请点击处理。如'.$cfg_doingouttime.'分钟后未处理，系统将奖励'.$cfg_doingoutfee.'。服务热线：'.$cfg_hotline.'";
                    $send_body['data']['remark']['color'] = "#FF0000";
                    $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $g_AccessToken;
                    $res = $jssdk->https_curl_json($url, $send_body, 'json');


                }*/
            }


            // 扣除奖励
            /*if (is_array($row_timeout) && isset($row_timeout['id']) && date("H",time())==23 ) {
                $last_outtime = $row_timeout['op_time'];
                if ($post_time - $last_outtime > $cfg_doingouttime * 60) {
                    //是否扣费
                    $row_fee = $dosql->GetOne("SELECT *  FROM  `#@__fee_log`  where `type`='order' and   orderid='$orderid'   AND jindu='4'  AND op='move' and qiandao='1'  order by id desc   ");
                    if (is_array($row_fee) && isset($row_fee['id'])) {
                        $last_feetime = $row_fee['op_time'];
                        // 判断是否  再次 超过
                        if ($post_time - $last_feetime > $cfg_doingouttime * 60) {
                            //再次超时 ，记录入库 并发送消息
                            foreach ($ids_arr as $key => $val) {
                                //获取工程师 openid
                                $m = $dosql->GetOne("select openid  from `#@__user`  where id='$val'");
                                $openid_str = $m['openid'];
                                //插入更新的状态
                                $remark = '工单签到后未及时完修或者反馈，再次扣除奖励' . $cfg_doingoutfee . '，再次';
                                $dosql->ExecNoneQuery("insert into `#@__fee_log`(`type`,orderid,op,op_time,jindu,manageid,fee,remark,qiandao,task,feetype) values ('order','$orderid','move','$post_time','$cfg_doingoutfee','$val','1',$remark,'1','$task_id','jiedanchaoshi')");
                                //推送超时提醒

                            }
                        }
                    } else {
                        //首次超时 ，记录入库 并发送消息
                        foreach ($ids_arr as $key => $val) {
                            //获取工程师 openid
                            $m = $dosql->GetOne("select openid  from `#@__user`  where id='$val'");
                            $openid_str = $m['openid'];
                            //插入更新的状态

                            $remark = '工单签到后未及时完修或者反馈，扣除奖励' . $cfg_doingoutfee . '首次';
                            $dosql->ExecNoneQuery("insert into `#@__fee_log`(`type`,orderid,op,op_time,jindu,manageid,fee,remark,qiandao,task,feetype) values ('order','$orderid','move','$post_time','4','$val','$cfg_doingoutfee','$remark','1','$task_id','jiedanchaoshi')");
                        }
                    }

                }
            }*/

        }
    }
}


?>
